package com.suxin.http.response.handler;

import com.alibaba.cloud.commons.io.IOUtils;
import com.suxin.http.model.HttpRestResult;
import com.suxin.http.response.HttpClientResponse;

import java.io.IOException;
import java.lang.reflect.Type;
import java.nio.charset.Charset;

/**
 * @author Tang
 * @classname StringResponseHandler
 * @description [  ]
 * @date 2023/3/2 22:15
 */
public class StringResponseHandler extends AbstractResponseHandler<String>{
    @Override
    protected HttpRestResult<String> convertHandler(HttpClientResponse response, Type type) throws IOException {
        final String body = IOUtils.toString(response.getBody(), Charset.defaultCharset());
        return new HttpRestResult<>(response.getStatusCode(),null,body, response.getHeaders());
    }
}
